package com.example.myexperiment1;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Stack;

public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView textView_before=(TextView)findViewById(R.id.textView_before);
        TextView textView_after=(TextView)findViewById(R.id.textView_after);

        Spinner spinner_before=(Spinner)findViewById(R.id.spinner_before);
        Spinner spinner_after=(Spinner)findViewById(R.id.spinner_after);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.items, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(
                android.R.layout.simple_spinner_dropdown_item);
        spinner_before.setAdapter(adapter);
        spinner_after.setAdapter(adapter);//添加spinner用于选择是正常计算还是进制换算或者是单位换算


        Button button_clear=(Button)findViewById(R.id.button_clear);//所有按钮的监听器都在这块儿
        Button button_left=(Button)findViewById(R.id.button_left);
        Button button_right=(Button)findViewById(R.id.button_right);
        Button button_del=(Button)findViewById(R.id.button_del);
        Button button_add=(Button)findViewById(R.id.button_add);
        Button button_sub=(Button)findViewById(R.id.button_sub);
        Button button_mul=(Button)findViewById(R.id.button_mul);
        Button button_div=(Button)findViewById(R.id.button_div);
        Button button_1=(Button)findViewById(R.id.button_1);
        Button button_2=(Button)findViewById(R.id.button_2);
        Button button_3=(Button)findViewById(R.id.button_3);
        Button button_4=(Button)findViewById(R.id.button_4);
        Button button_5=(Button)findViewById(R.id.button_5);
        Button button_6=(Button)findViewById(R.id.button_6);
        Button button_7=(Button)findViewById(R.id.button_7);
        Button button_8=(Button)findViewById(R.id.button_8);
        Button button_9=(Button)findViewById(R.id.button_9);
        Button button_0=(Button)findViewById(R.id.button_0);
        Button button_power=(Button)findViewById(R.id.button_power);
        Button button_percent=(Button)findViewById(R.id.button_percent);
        Button button_point=(Button)findViewById(R.id.button_point);
        Button button_equal=(Button)findViewById(R.id.button_equal);
        Button button_cos=(Button)findViewById(R.id.button_cos);
        Button button_sin=(Button)findViewById(R.id.button_sin);
        Button button_operate=(Button)findViewById(R.id.button_operate);
        Button button_menu=(Button)findViewById(R.id.button_menu);
        StringBuilder str=new StringBuilder();

        button_0.setOnClickListener(view -> {
            str.append(0);
            textView_before.setText(str);
        });
        button_1.setOnClickListener(view -> {
            str.append(1);
            textView_before.setText(str);
        });
        button_2.setOnClickListener(view -> {
            str.append(2);
            textView_before.setText(str);
        });
        button_3.setOnClickListener(view -> {
            str.append(3);
            textView_before.setText(str);
        });
        button_4.setOnClickListener(view -> {
            str.append(4);
            textView_before.setText(str);
        });
        button_5.setOnClickListener(view -> {
            str.append(5);
            textView_before.setText(str);
        });
        button_6.setOnClickListener(view -> {
            str.append(6);
            textView_before.setText(str);
        });
        button_7.setOnClickListener(view -> {
            str.append(7);
            textView_before.setText(str);
        });
        button_8.setOnClickListener(view -> {
            str.append(8);
            textView_before.setText(str);
        });
        button_9.setOnClickListener(view -> {
            str.append(9);
            textView_before.setText(str);
        });
        button_left.setOnClickListener(view -> {
            str.append('(');
            textView_before.setText(str);
        });
        button_right.setOnClickListener(view -> {
            str.append(')');
            textView_before.setText(str);
        });
        button_point.setOnClickListener(view -> {
            if(str.length()==0) {
                str.append(0).append(".");
                textView_before.setText(str);
            }
            else{
                str.append('.');
                textView_before.setText(str);
            }
        });

        button_power.setOnClickListener(view -> {
            str.append('^');
            textView_before.setText(str);
        });

        button_add.setOnClickListener(view -> {
            str.append('+');
            textView_before.setText(str);
        });

        button_sub.setOnClickListener(view -> {
            str.append('-');
            textView_before.setText(str);
        });

        button_mul.setOnClickListener(view -> {
            str.append('*');
            textView_before.setText(str);
        });

        button_div.setOnClickListener(view -> {
            str.append('/');
            textView_before.setText(str);
        });

        button_del.setOnClickListener(view -> {
            str.deleteCharAt(str.length()-1);
            textView_before.setText(str);
        });

        button_clear.setOnClickListener(view -> {
            str.delete(0,str.length());
            textView_before.setText(str);
        });

        button_menu.setOnClickListener(view -> {
            menu();
        });

        button_sin.setOnClickListener(view -> {

        });

        button_cos.setOnClickListener(view -> {

        });

        button_equal.setOnClickListener(view -> {

        });

        button_percent.setOnClickListener(view -> {

        });







    }

    public void cal(){//用于按下等号之后的计算
        
    }

    public void menu(){//菜单界面
        AlertDialog.Builder buider =new AlertDialog.Builder(MainActivity.this);
        buider.setMessage("请选择").setTitle("菜单界面");
        buider.setPositiveButton("帮助", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Toast.makeText(MainActivity.this,"这是帮助",Toast.LENGTH_LONG).show();
            }
        });
        buider.setNegativeButton("退出", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Toast.makeText(MainActivity.this,"退出",Toast.LENGTH_SHORT).show();
            }
        });
        buider.show();
    }
    



    

    

}
